(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	$(function() {
		initSmPages();
		window.onresize = function() {
			initSmPages();
		};
		initStudent();
		pagebtns();
	});

	function initStudent() {
		var userkey = $("#user-name", parent.document).attr("key");
		var usercode = $("#user-name", parent.document).attr("code");
		var data = {
			cmd : "getStudentByUserCode",
			model : "user",
			userKey : userkey,
			data : {
				usercode : usercode
			},
			remark : ""
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res) {
			if (res.result == 1 && res.data != undefined && res.data != "") {
				var list = res.data;
				var imgContent = "";
				for (var i = 0; i < list.length; i++) {
					if(i == 0){
						imgContent += "<div class='students-choice students-choice-select' classcode='" + list[i].classcode + "' studentcode='" + list[i].studentcode + "' name = '"+list[i].name+"' rfid='" + list[i].rfid +"' title = '"+list[i].name+"'><div class='students-choice-img'><img src=\"../../../../../"+ServiceName+list[i].headimg+"\" width='100%' height='100%'/></div><div class='students-choice-name'>"+substr(list[i].name,4)+"</div></div>";
					}else{
						imgContent += "<div class='students-choice' classcode='" + list[i].classcode + "' studentcode='" + list[i].studentcode + "' name = '"+list[i].name+"' rfid='" + list[i].rfid +"' title = '"+list[i].name+"'><div class='students-choice-img'><img src=\"../../../../../"+ServiceName+list[i].headimg+"\" width='100%' height='100%'/></div><div  class='students-choice-name'>"+substr(list[i].name,4)+"</div></div>";
					}
				}
				$(".dialog-students-contents").empty();
				$(".dialog-students-contents").append(
						imgContent);
				$(".students-choice").unbind("click");
				$(".students-choice").click(
						function() {
							$(".students-choice").removeClass(
									"students-choice-select");
							$(this).addClass(
									"students-choice-select");

						});
			}
		}, null, null);					
	}

	function pagebtns() {
		/*$(".left-menu").click(
				function() {
					$(".left-menu-sec").hide();
					if ($(this).attr("model") == "充值查询") {
						$("#news-op").show();
						var Hei = $("#news-op .menu-sec").length
								* $(".menu-sec").height();
						$("#news-op").height(Hei);
					}
				});*/
		$(".menu-sec").click(function() {
			var model = $(this).attr("title");
			$(".menu-sec").removeClass("menu-sec-select");
			$(this).addClass("menu-sec-select");
			if (model == "消费查询") {
				changePage(PageUrl.pconsumeUrl);
			} else if (model == "充值查询") {
				changePage(PageUrl.ppayUrl);
			}
		});

		$(".dialog-display-btnshow").click(function() {
			$(".dialog-display-btnshow").hide();
			$(".dialog-display-btnhide").show();
			$(".student-choice-classdia").animate({
				right : "0px"
			});
		});
		$(".dialog-display-btnhide").click(function() {
			$(".dialog-display-btnshow").show();
			$(".dialog-display-btnhide").hide();
			$(".student-choice-classdia").animate({
				right : "-120px"
			});
		});
	}
	function substr(str,len){
		if(str != undefined){
			if(str.length > len){
				str = str.substring(0,len-2)+"...";
				return str;
			}else{
				return str;
			}
		}else{
			return "";
		}
	}
	function changePage(pageUrl) {
		$("#right-iframe").attr("src", pageUrl);
	}
	function initSmPages() {
		var bodyRW = $(".index-body", parent.document).width()
				- $(".body-left").width() - 6;
		$(".body-right").width(bodyRW);

		var leftCH = $(".body-left").height() - $(".left-title").height() - 1;
		$(".left-content").height(leftCH);
	}
})();